<?php

namespace app\api\controller;

use app\admin\model\Member AS MemberMdl;

/**
 * 村民接口
 * Class Organization
 */
class Member extends BaseController
{

    /**
     * 获取村民列表
     *
     * @return \think\response\Json
     */
    public function getMemberList()
    {
        $param = self::getHttpParam();

        $start = 0;
        $length = 20;
        if (empty($param->villageId)) {
            return show(config('status.ERROR_STATUS'), self::NOT_PARAM, 'villageId不能为空');
        }

        $where = [
            'villageId' => $param->villageId,
            'isDelete' => 2
        ];
        $fields = 'name, avatar, gender, mobile';

        if (!empty($param->start)) {
            $start = $param->start;
        }
        if (!empty($param->length)) {
            $length = $param->length;
        }

        $result = MemberMdl::where($where)->order('createDate DESC')->limit($start, $length)->field($fields)->select();
        $total = MemberMdl::where($where)->count();

        if (empty($result)) {
            return show(config('status.ERROR_STATUS'), self::NOT_DATA, '未查到村民');
        }

        return showTotal(config('status.SUCCESS_STATUS'), self::MSG_SUCCESS, $result, $total);
    }
}